<!--
 * @Description: 精选题库
 * @Author: wangying
 * @Date: 2022-09-17 11:42:41
 * @LastEditors: yue
 * @LastEditTime: 2022-09-21 14:34:24
-->

<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card shadow="never">
        <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
          <el-tab-pane label="全部" name="first">
            <tab-choice />
          </el-tab-pane>

          <el-tab-pane label="待审核" name="second">
            <tab-choice :chk-state="0" />
          </el-tab-pane>

          <el-tab-pane label="已审核" name="three">
            <tab-choice :chk-state="1" />
          </el-tab-pane>
          <el-tab-pane label="已拒绝" name="four">
            <tab-choice :chk-state="2" />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import { choice } from '@/api/hmmm/questions.js'
import {
  questionType,
  difficulty,
  chkType,
  publishType
} from '@/api/hmmm/constants.js'
import TabChoice from '@/components/Choices/TabChoice'

export default {
  components: {
    TabChoice
  },
  data() {
    return {
      activeName: 'second',
      tableData: [],
      total: 0, // 总数
      page: {
        page: 1, // 当前页码
        pagesize: 100, //
        choiceState: ''
      },
      showDialog: false
    }
  },
  created() {
    this.getchoice()
  },
  methods: {
    // 页码加载
    async getchoice() {
      try {
        const { data } = await choice(this.page)
        this.page.pagesize = data.pagesize
        this.total = data.counts
        this.tableData = data.items
      } catch (error) {
        console.log(error)
      }
    },
    // 点击页码切换
    changePage(newPage) {
      this.page.page = newPage
    },
    // 点击切换分页数据
    handleClick() {
      if (this.activeName === 'first') {
        // 全部
        this.getchoice()
      } else if (this.activeName === 'second') {
        // 待审核
        this.page.chkState = 0
        this.getchoice()
      } else if (this.activeName === 'three') {
        // 已审核
        this.page.chkState = 1
        this.getchoice()
      } else {
        // 已拒绝
        this.page.chkState = 2
        this.getchoice()
      }
    },

    // 格式化题型，难度，类型
    formatquestionType(row, column, cellValue, index) {
      const obj = questionType.find((item) => item.value + '' === cellValue) // cellValue是单元格值
      return obj ? obj.label : '未知'
    },
    formatdifficulty(row, column, cellValue, index) {
      const obj = difficulty.find((item) => item.value + '' === cellValue) // cellValue是单元格值
      return obj ? obj.label : '未知'
    },
    formatchkType(row, column, cellValue, index) {
      const obj = chkType.find((item) => item.value + '' === cellValue) // cellValue是单元格值
      return obj ? obj.label : '未知'
    },
    formatpublishType(row, column, cellValue, index) {
      const obj = publishType.find((item) => item.value + '' === cellValue) // cellValue是单元格值
      return obj ? obj.label : '未知'
    }
  }
}
</script>

<style scoped></style>
